package cn.edu.njust.pojo.bo;


import lombok.Data;

/**
 * 统一响应参数
 *
 * @author wangs
 * @date 2025/4/13 1:23
 * @since 2.0.0
 */
@Data
public class RestResult<T> {

    private String code;

    private String errMessage;

    private T data;

    public static <T> RestResult<T> success() {
        RestResult<T> restResult = new RestResult<>();
        restResult.setCode("200");
        restResult.setErrMessage("success");
        return restResult;
    }

    public static <T> RestResult<T> success(T data) {
        RestResult<T> restResult = new RestResult<>();
        restResult.setCode("200");
        restResult.setData(data);
        restResult.setErrMessage("success");
        return restResult;
    }

    public static <T> RestResult<T> error(String errMessage) {
        RestResult<T> restResult = new RestResult<>();
        restResult.setCode("600");
        restResult.setErrMessage(errMessage);
        return restResult;
    }

    public static <T> RestResult<T> error(String code, String errMessage) {
        RestResult<T> restResult = new RestResult<>();
        restResult.setCode(code);
        restResult.setErrMessage(errMessage);
        return restResult;
    }
}
